# -*- coding:utf-8 -*-
"""
Author：Administrator
Date:2023年02月23日
"""

import docx
from docx.shared import Cm,Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT

def setAttrs(rootElement,elements,attrs):
	for element in elements:
		myElement=rootElement.find(docx.oxml.ns.qn(element))
		if myElement is None:
			myElement=docx.oxml.OxmlElement(element)
			rootElement.append(myElement)
		for key in attrs:
			myElement.set(docx.oxml.ns.qn(key),attrs[key])



myDocument=docx.Document('新员工.docx')
myTable=myDocument.tables[0]
myTablePr=myTable._element.tblPr
myElements=['w:top','w:left','w:bottom','w:right']
# 定义元素属性键值对
myAttrs={'w:val':'single','w:color':'000000','w:sz':'24'}
# 遍历表格的所有行,自定义行的边框
for myRow in myTable.rows:
	myTr=myRow._element
	myTblPrEx=myRow._element.first_child_found_in('w:tblPrEx')
	if myTblPrEx is None:
		myTblPrEx=docx.oxml.OxmlElement('w:tblPrEx')
		myTr.append(myTblPrEx)
	myTblBorders=docx.oxml.OxmlElement('w:tblBorders')
	myTblPrEx.append(myTblBorders)
	setAttrs(myTblBorders,myElements,myAttrs)

myDocument.save('02散文名篇.docx')


